import { g_db } from 'db/state';

const get_rgb = (v) => {
    const tmp = v.split("-");
    const rgb = tmp[1];
    if (!rgb) {
        return [100, 100, 100, "black"];
    }

    const h = rgb[0];
    const n = parseInt(rgb.slice(1), 10);

    const tc = n < 200 ? "white" : "black";

    if (h === "R") {
        return [n, 0, 0, tc];
    } else if (h === "G") {
        return [0, n, 0, tc];
    } else if (h === "B") {
        return [0, 0, n, tc];
    }

    return [100, 100, 100, tc];
};

const split_psn = (v) => {
    if (!v) {
        return v;
    }

    if (v.length !== 8) {
        return v;
    }

    return `${v[0]}${v[1]}${v[2]}${v[4]}${v[6]} - ${v[3]}${v[5]}${v[7]}`;
};

const box_name = () => {
    const tp = g_db.boxtp();

    if (tp === "outer") {
        return "外圈箱号";
    } else if (tp === "inner") {
        return "内圈箱号";
    }

    return "箱号";
};

export {box_name, split_psn, get_rgb};
